//
//  AXFNewFutureController.m
//  aixinfeng005
//
//  Created by 汪舟 on 16/10/11.
//  Copyright © 2016年 BBSWaitting. All rights reserved.
//

#import "AXFNewFutureController.h"
#import "AXFHomeViewController.h"
#define KImageCount 4

@interface AXFNewFutureController ()<UIScrollViewDelegate>
@property (nonatomic, strong) UIScrollView *scroll;
@property (nonatomic, strong) UIPageControl *pageControl;
@end

@implementation AXFNewFutureController

- (instancetype)initWithFrame:(CGRect)frame
{
	self = [super initWithFrame:frame];
	if (self) {
		[self setupUI];
	}
	return self;
}
- (void)setupUI
{
//创建并添加UIScrollView
	_scroll = [[UIScrollView alloc]init];
	_scroll.frame = self.bounds;
	[self addSubview:_scroll];
	
	CGFloat width = _scroll.bounds .size.width;
	CGFloat height = _scroll.bounds.size.height;
	
	for (int i = 0; i<KImageCount; i++) {
		UIImageView *imageView = [[UIImageView alloc]init];
		CGFloat imageX = (i)*width;
		CGFloat imageY = 0;
		imageView.frame = CGRectMake(imageX, imageY, width, height);
//		http://iosapi.itcast.cn/loveBeen/ad.json.php
		
		imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"guide_35_%d",i+1]];
		[_scroll addSubview:imageView];
		if (i == KImageCount - 1) {
			[self setupLastImageView:imageView];
		}
		
	}
	_pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(150, 550, 100, 75)];
	_pageControl.numberOfPages = KImageCount;
	_pageControl.pageIndicatorTintColor = [UIColor redColor];
	_pageControl.currentPageIndicatorTintColor = [UIColor blueColor];
	[self addSubview:_pageControl];
	
	_scroll.contentSize = CGSizeMake(KImageCount *width, 0);
	_scroll.pagingEnabled = YES;
	_scroll.showsVerticalScrollIndicator = NO;
	_scroll.showsHorizontalScrollIndicator = NO;
	_scroll.showsVerticalScrollIndicator = NO;
	_scroll.bounces = NO;
	_scroll.delegate = self;
	
}
- (void)setupLastImageView:(UIImageView *)imageView
{
	imageView.userInteractionEnabled = YES;
	UIButton *btn = [[UIButton alloc]init];
	btn.frame = CGRectMake(150, 500, 100, 75);
	[btn setTitle:@"点击进入" forState:UIControlStateNormal];
	[btn setTitleColor:[UIColor magentaColor] forState:UIControlStateNormal];
	[btn addTarget:self action:@selector(junpMainPage:) forControlEvents:UIControlEventTouchUpInside];
	[imageView addSubview:btn];

}
#pragma mark - UIScrollViewDelegate
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
	CGPoint offset = scrollView.contentOffset;
	CGFloat offsetX = offset.x;
	int pageNum = (offsetX + 0.5*_scroll.frame.size.width)/(_scroll.frame.size.width);
	_pageControl.currentPage = pageNum;

}
- (void)junpMainPage:(UIButton *)btn
{
	//动画的方式让imageView放大及完全透明
	[UIView animateWithDuration:0.2 animations:^{
		//    让按钮的父控件，也就当前点击的按钮所在的imageView放大
		btn.superview.transform = CGAffineTransformMakeScale(2, 2);
		//        让imageView透明
		btn.superview.alpha = 0;
	} completion:^(BOOL finished) {
		//        让新特性界面自定义视图直接从父控件上移除
		//        动画完成之后把自定义的新特性view直接从父控件中移除
		[self removeFromSuperview];
	}];
}

@end
